package com.ycw.servlet.guoguo;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.ycw.dao.LogisticsDao;
import com.ycw.dao.impl.LogisticsDaoImpl;

/**
 * Servlet implementation class AlterLogisticsDataById
 */
@WebServlet("/alterLogisticsDataByIdServlet")
public class AlterLogisticsDataByIdServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 工号修改不能重
		String jobnumber = request.getParameter("l_jobnumber");
		Integer l_jobnumber = Integer.parseInt(jobnumber);
		LogisticsDao ld = LogisticsDaoImpl.getInstance();
		/**
		 * 修改工号不能重 如果存在返回false ，表示重复 不存在时返回true,表示可以添加
		 */
		boolean notFoundl_id = ld.queryLogisticsL_jobnumber(l_jobnumber);

		boolean alterLogisticsDataById = false;
		// if (notFoundl_id) {

		String l_name = request.getParameter("l_name");
		String age = request.getParameter("l_age");
		Integer l_age = Integer.parseInt(age);
		String l_gender = request.getParameter("l_gender");
		String l_phone = request.getParameter("l_phone");
		// 身份证
		String l_number = request.getParameter("l_number");
		// 住址
		String l_address = request.getParameter("l_address");
		// 根据id修改 这个必须要有
		String id = request.getParameter("l_id");
		Integer l_id = Integer.parseInt(id);

		List<Object> list = new ArrayList<>();
		list.add(l_jobnumber);
		list.add(l_name);
		list.add(l_age);
		list.add(l_gender);
		list.add(l_phone);
		list.add(l_number);
		list.add(l_address);
		list.add(l_id);
		alterLogisticsDataById = ld.alterLogisticsDataById(list);
		// }
		Map<String, Object> map = new HashMap<>();
		/**
		 * notFoundL_id=true表示工号数据不重复 只有notFoundL_id=true时才可以添加
		 * alterLogisticsDataById=true表示修改成功
		 */
		map.put("notFoundl_id", notFoundl_id);
		map.put("alterLogisticsDataById", alterLogisticsDataById);

		String resJSON = JSON.toJSONString(map);
		PrintWriter out = response.getWriter();
		out.write(resJSON);

	}

}
